import request from '@/router/axios';

export const getList = (current, size, params,sortType) => {
  return request({
    url: '/api/beetles-offer/creativerequest/page',
  method: 'get',
  params: {
...params,
    sortType,
    current,
    size,
}
})
}
export const selectCreative = (offerid) => {
  return request({
    url: '/api/beetles-offer/creativerequest/selectCreative',
    method: 'get',
    params: {
      offerid:offerid
    }
  })
}
export const selectAll = (offerid) => {
  return request({
    url: '/api/beetles-offer/creativerequest/selectall',
    method: 'get',
    params: {
      offerid:offerid
    }
  })
}
export  const  selectDetail = (offerid) => {
  return  request({
    url: '/api/beetles-offer/creativerequest/selectDetail',
    method: 'get',
    params: {
      offerid:offerid
    }
  })
}
export const selectDetailHis = (id) => {
  return request({
    url: '/api/beetles-offer/creativerequest/selectDetailHis',
    method: 'get',
    params: {
      offerid:id
    }
  })
}
/*获取被拒素材列表*/
export const getRejectedCreativeList = (current, size, offerId, params, creativeRequestId) => {
  return request({
    url: '/api/beetles-offer/creativerequest/get-rejected-creatives-list',
    method: 'get',
    params: {
      ...params,
      offerId,
      creativeRequestId,
      current,
      size,
    }
  })
}

// 需求沟通的详情接口
export const getDetail = (id) => {
  return request({
    url: '/api/beetles-offer/creativerequest/detail',
    method: 'get',
    params: {
      id
    }
  })

}


export const updateDesigner = (id,designers,offerId) => {
  return request({
    url: '/api/beetles-offer/creativerequest/updateDesigner',
    method: 'get',
    params: {
      id,
      designers,
      offerId
    }
  })
}

export const updateUrgency = (id,urgency) => {
  return request({
    url: '/api/beetles-offer/creativerequest/updateUrgency',
    method: 'get',
    params: {
      id,
      urgency,
    }
  })
}

//获取当前订单下设计师名单
export const getRequestUserList = (offerIds, requestIds, userType) => {
  return request({
    url: '/api/beetles-offer/creativerequest/get-request-user-list',
    method: 'get',
    params: {
      offerIds,
      requestIds,
      userType,
    }
  })
}

//获取当前订单下设计师名单
export const getOfferDesigner = (offerId) => {
  return request({
    url: '/api/beetles-business/offer/get-designer-select',
    method: 'get',
    params: {
      offerId
    }
  })
}

//获取当前订单下设计师负责人名单
export const getOfferDesignerManager = (offerId) => {
  return request({
    url: '/api/beetles-business/offer/get-designer-manager-select',
    method: 'get',
    params: {
      offerId
    }
  })
}

//获取当前订单下优化师名单
export const getOfferOptimizer = (offerId) => {
  return request({
    url: '/api/beetles-business/offer/get-admin-and-optimizer-select',
    method: 'get',
    params: {
      offerId
    }
  })
}


// 获取被优化师拒绝的素材
export const getRejectedList = (rejectedIds) => {
  return request({
    url: '/api/beetles-offer/creativerequest/get-rejected-creatives-select',
    method: 'get',
    params: {
      rejectedIds
    }
  })

}

// 删除接口
export const remove = (ids) => {
  return request({
    url: '/api/beetles-offer/creativerequest/remove',
    method: 'post',
    params: {
      ids,
    }
  })
}

// 需求沟通页面的新增和编辑按钮
export const submit = (row) => {
  return request({
    url: '/api/beetles-offer/creativerequest/submit',
    method: 'post',
    data: row
  })
}

// 需求沟通页面的新增和编辑按钮
export const saveCreative = (data, files) => {
  return request({
    url: '/api/beetles-offer/creativerequest/save-creative-request',
    method: 'post',
    data: {
      creativeRequest: JSON.stringify(data),
      appendFiles: files,
    }
  })
}


// 新版需求沟通页面的保存，暂时保留，有可能被submit替换
export const saveCreativeRequest = (row) => {
  return request({
    url: '/api/beetles-offer/creativerequest/save-creative-request',
    method: 'post',
    data: row
  })
}

// 获取已有需求列表接口
export const getCreativeRequestList = (offerId) => {
  return request({
    url: '/api/beetles-offer/creativerequest/get-creative-request-list',
    method: 'get',
    params: {
      offerId
    }
  })
}

export const addProductCreative = (data) =>{
  return request({
    url:'/api/beetles-offer/creativerequest/upload-finished-creative',
    method:'post',
    data:data
  })
}

export const addProductTagsCreative = (data) =>{
  return request({
    url:'/api/beetles-offer/creativerequest/upload-finished-tags-creative',
    method:'post',
    data:data
  })
}

//上传成品素材
// export const addProductCreative = (row, files, cd) => {
//   const formData = new FormData();
//   for (var index in files) {
//     formData.append('files', files[index].raw);
//   }
//   formData.append('creative', JSON.stringify(row))
//   return request({
//     url: '/api/beetles-offer/creativerequest/upload-finished-creative',
//     method: 'post',
//     headers: {
//       "Content-Type": "multipart/form-data"
//     },
//     timeout: 3600 * 1000,
//     data: formData,
//     onUploadProgress: (progressEvent) => {
//       if (progressEvent.lengthComputable) {
//         cd(progressEvent);
//       }
//     }
//   })
// }

//获取用户角色
export const getUserRole = () => {
  return request({
    url: '/api/blade-user/get-user-role',
    method: 'get'
  })
}

//获取用户ID
export const getUserId = () => {
  return request({
    url: '/api/blade-user/get-by-ids',
    method: 'get'
  })
}

//定时获取成品状态
export const getProduct = (data) =>{
  return request({
    url:'/api/beetles-offer/creativerequest/refresh-finished-creative',
    method:'post',
    data:data
  })
}

//获取设计师名单
export const getDesignerSelect = () => {
  return request({
    url: '/api/blade-user/get-designer-select',
    method: 'get'
  })
}

/**
 * 当选择素材库素材时： 请求creative.js 的getList接口
 * 当选择原始素参考素材时： 请求origincreative.js的getList接口
 * 当选择被拒素材时：请求creative.js 的getList接口，参数传: {Status: 3}表示被拒素材
 */

export const updateScheduleStatus = (params) => {
  return request({
    url: '/api/beetles-offer/creativerequest/updateScheduleStatus',
    method: 'get',
    params: {
      ...params
    }
  })
}

export const updateScheduleDate = (params) => {
  return request({
    url: '/api/beetles-offer/creativerequest/updateScheduleDate',
    method: 'get',
    params: {
      ...params
    }
  })
}

// 更新排期分配
export const updateRequsetSchedule = data => {
  return request({
    url: '/api/beetles-offer/creativerequest/update-requset-schedule',
    method: 'post',
    data
  })
}
// 激活
export const updateDemandStatusToActivateByBatch = data => {
  return request({
    url: '/api/beetles-offer/creativerequest/updateDemandStatusToActivateByBatch',
    method: 'post',
    data
  })
}



//批量完成
export const updateScheduleStatusToDoneByBatch = data => {
  return request({
    url: '/api/beetles-offer/creativerequest/updateScheduleStatusToDoneByBatch',
    method: 'post',
    data
  })
}

//批量关闭
export const updateDemandStatusToCloseByBatch = data => {
  return request({
    url: '/api/beetles-offer/creativerequest/updateDemandStatusToCloseByBatch',
    method: 'post',
    data
  })
}
